//test
export const increment = ({commit}) => {
    commit('INCREMENT')
}
export const decrement = ({commit}) => {
    commit('DECREMENT')
}


const actions = {

    accountRole(context, uType ) {
        console.log(context)
        return context.commit('SET_ROLE', role(uType))
    },



    login({ commit }, uType) {
        // const { userName, uType } = userInfo;
        commit("SET_ROLE", role(uType))
        // setRole(data.token)

    },


    getInfo({ commit, state }) {
        return new Promise((resolve, reject) => {
            getInfo(state.role).then(response => {
                const { data } = response

                if (!data) {
                    reject('Verification failed, please Login again.')
                }
                const { role, name} = data
                if (!role || role === "") {
                    reject('getInfo: roles must be a non-null array!')
                }
                commit('SET_ROLE', role)
                commit('SET_NAME', name)

                /*const { roles, name} = data

                // roles must be a non-empty array
                if (!roles || roles.length <= 0) {
                    reject('getInfo: roles must be a non-null array!')
                }
                commit('SET_ROLES', roles)*/



                resolve(data)
            }).catch(error => {
                reject(error)
            })
        })
    },

}



// export const login = ({commit}) => {
//     commit('Logins')
// }
